def i(number):
    for x in range(2, number):
        if number % x == 0:
            return False
    return True


prime = [x for x in range(10, 10000) if i(x)]
slovar = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9,
}
stroka = input().split()
try:
    line = slovar[stroka[0]] * 100 + slovar[stroka[1]] * 10 + slovar[stroka[2]]
    rast = 1000
    zap = 0
    for elem in prime:
        if abs(elem - line) < rast:
            rast = abs(elem - line)
            zap = elem
    print(zap)
except:
    print("Wrong input")